//
//  ShopView.m
//  shop
//
//  Created by student on 16/2/28.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ShopView.h"
#import "ShopPlist.h"

@implementation ShopView

//懒加载 创建子控件对象
- (UIImageView *)picture
{
    if (_picture == nil)
    {
        _picture = [[UIImageView alloc] init];
        [self addSubview:_picture];
    }
    return _picture;
}

- (UILabel *)totalCount
{
    if (_totalCount == nil)
    {
        _totalCount = [[UILabel alloc] init];
        _totalCount.font = [UIFont systemFontOfSize:15];
        _totalCount.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_totalCount];
    }
    return _totalCount;
}

- (UILabel *)alreadyCount
{
    if (_alreadyCount == nil)
    {
        _alreadyCount = [[UILabel alloc] init];
        _alreadyCount.font = [UIFont systemFontOfSize:13];
        _alreadyCount.textColor = [UIColor grayColor];
        _alreadyCount.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_alreadyCount];
    }
    return _alreadyCount;
}

- (UIButton *)shoppingCart
{
    if (_shoppingCart == nil)
    {
        _shoppingCart = [[UIButton alloc] init];
        [self addSubview:_shoppingCart];
    }
    return _shoppingCart;
}

//设定子控件的frame
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    int width = self.frame.size.width;
    int height = self.frame.size.height;
    
    self.picture.frame = CGRectMake(0, 0, width, height-40);
    self.totalCount.frame = CGRectMake(5, height-40, width-40, 20);
    self.alreadyCount.frame = CGRectMake(5, height-20, width-40, 20);
    self.shoppingCart.frame = CGRectMake(width-40, height-40, 40, 40);
}

//设置参数
- (void)setShop:(ShopPlist *)shopPlist
{
    self.picture.image = [UIImage imageNamed:shopPlist.picture];
    self.totalCount.text = [@"总需人次:" stringByAppendingString:shopPlist.totalCount];
    self.alreadyCount.text = [@"参与:" stringByAppendingString:shopPlist.alreadyCount];
    [self.shoppingCart setImage:[UIImage imageNamed:@"tfw_gwc"] forState:UIControlStateNormal];
}

@end
